using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Web;
using FeedBurner.Utility;

namespace FeedBurner.Operations
{
    internal class ResyncFeed
    {
        public void Resync(string username, string password, Int64 feedID, string uri)
        {

           StringBuilder Query = new StringBuilder
               (string.Format("?user={0}&password={1}", username, password));

            if (!string.IsNullOrEmpty(uri))
                Query.AppendFormat("&uri={0}",
                    HttpUtility.UrlEncode(uri, Encoding.ASCII));
            else if (feedID > 0)
                Query.AppendFormat("&id={0}", feedID);
            else
                throw new ArgumentException
                    ("One of feed ID or Uri must be provided.");

            ReSyncFeed(DataManager.Post(Urls.ResyncUrl() + Query.ToString(), ""));
        }

        private void ReSyncFeed(string Output)
        {
            if (!string.IsNullOrEmpty(Output))
            {
                Feed Result = new Feed();
                XmlDocument Xml = new XmlDocument();
                Xml.LoadXml(Output);

                Errors.CheckError(Xml);
            }
        }
    }
}
